package com.zlc.workflow.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

@Getter
@AllArgsConstructor
public enum WorkflowStatusEnum {


    DRAFT("DRAFT","草稿"),
    PROCESSING("PROCESSING","进行中"),
    FINISH("FINISH","结束"),
    TERMINATION("TERMINATION","终止"),
    ;
    private String status;
    private String desc;

    public static WorkflowStatusEnum  getStatus(String status){
        WorkflowStatusEnum[] statusList = values();
        for(WorkflowStatusEnum statusEnum : statusList){
            if(statusEnum.status.equals(status)){
                return statusEnum;
            }
        }
        return null;
    }

    public static boolean activeInstance(String status){
        return DRAFT.getStatus().equals(status) || PROCESSING.getStatus().equals(status);
    }

    public static boolean histInstance(String status){
        return FINISH.getStatus().equals(status) || TERMINATION.getStatus().equals(status);
    }

    public static String getStatusName(String status){
        WorkflowStatusEnum statusEnum = getStatus(status);
        return Objects.nonNull(statusEnum)?statusEnum.getDesc():null;
    }
}
